
////////////////////////////////////////////////////////////////////////////////
// Filename		Query.h
// Author		soyenze
// Date			2011-10-28
// Comment		
////////////////////////////////////////////////////////////////////////////////
#pragma once
#include <vector>
#include <fstream>

class Query
{
public:
	enum TextType
	{
		TT_HEAD = 0,
		TT_NUM,
		TT_DOM,
		TT_TITLE,
		TT_DESC,
		TT_NARR,
		TT_CON,
		TT_FAC,
		TT_DEF,
		TT_ENCHANT,
		TT_COUNT // Always at last
	};

	static std::vector<std::string> ContentTagList;

	static void Initialize();
	static Query* CreateFromStream(std::ifstream& stream);

public:
	Query(void);
	virtual ~Query(void);
	void AddText(const char* str) { AddText(std::string(str)); }
	void AddText(std::string& str) { m_TextList.push_back(str); }
	std::string& GetText(Query::TextType type) { return m_TextList[type]; }
	
private:
	static void removeAll(std::string& target, std::string& find);
	static char removeSpecialCharacter(char in);
	std::vector<std::string> m_TextList;

	static inline std::string trimLeft(const std::string& str)
	{
		std::string::size_type n = str.find_first_not_of(" \t\v\n");
		return n == std::string::npos ? str : str.substr(n, str.length());
	}

	static inline std::string trim_right(const std::string& str)
	{
	    std::string::size_type n = str.find_last_not_of(" \t\v\n");
		return n == std::string::npos ? str : str.substr(0, n + 1);
	}

	static std::string trim(const std::string& str)
	{
		return trimLeft(trim_right(str));
	}
};